## init
import ee
import geemap
geemap.set_proxy(port=7890)
Map = geemap.Map()

# composite
# -----------------------------------------------------------------------------
# get monthly data from daily data



# filtering
# -----------------------------------------------------------------------------
# filter imageCollection by date range
Cols = ee.ImageCollection("LANDSAT/LC08/C02/T1_L2")
subCols = Cols.filterDate("2016-01-01","2016-02-01")

# filter imageCollection by boundary of rectangle

# filter imageCollection by point


# find the image that closet to the date we interested

# function to find the nearest image to the date we interested
def find_nearest_date_image(Cols,dateOfInterest):
    dateOfInterest = ee.Date(dateOfInterest)
    def set_image_dist(image):
        image.set(
            'dateDist',
            ee.Number(image.get('system:time_start')).subtract(dateOfInterest.millis()).abs)
        return image
    return Cols.map(set_image_dist).sort("dateDist").first()
